import { Image, Switch, Tag } from "antd";
import { EyeFilled } from "@ant-design/icons";

function getcolumns(enable) {
  return {
    columns: [
      {
        title: "头像",
        key: "head_image",
        dataIndex: "head_image",
        hideInForm: true,
        ellipsis: true,
        width: 66,
        search: false,
        render: (text, row) => {
          return (
            <Image
              src={row?.head_image ?? "./user_s.png"}
              style={{ width: 28, height: 28 }}
              preview={{
                mask: <EyeFilled />,
              }}
            />
          );
        },
        colProps: {
          span: 24,
        },
      },
      {
        title: "公司名称",
        key: "name",
        dataIndex: "name",
        copyable: true,
        ellipsis: true,
        hideInTable: true,
        hideInSearch: true,
        hideInForm: true,
        formItemProps: {
          rules: [
            {
              required: true,
              message: "此项为必填项",
            },
          ],
        },
      },

      {
        title: "真实姓名",
        key: "real_name",
        dataIndex: "real_name",
        ellipsis: true,
        hideInForm: true,
      },
      {
        title: "手机号",
        key: "phone",
        dataIndex: "phone",
        ellipsis: true,
        formItemProps: {
          rules: [
            {
              required: true,
              message: "此项为必填项",
            },
          ],
        },
      },
      {
        title: "密码",
        key: "password",
        dataIndex: "password",
        valueType: "password",
        hideInSearch: true,
        hideInDescriptions: true,
        formItemProps: {
          rules: [
            {
              required: true,
              message: "此项为必填项",
            },
            {
              pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=(?:\D*\d){3})(?=.*[$@$!%*?~.^-_+=&])[A-Za-z\d$@$!%*?&]{8,}/,
              message: "至少包含八个字符，一个大写字母，一个小写字母，三个数字和一个特殊字符"
            }
          ],
        },
        hideInTable: true,
      },
      {
        title: "邮箱",
        key: "email",
        dataIndex: "email",
        ellipsis: true,
      },
      {
        title: "职位",
        key: "position",
        dataIndex: "position",
        ellipsis: true,
      },
      {
        title: "角色",
        key: "role_ids",
        dataIndex: "role_ids",
        ellipsis: true,
        search: false,
        mode:"multiple",
        valueType: "select",
        colProps: {
          span: 24,
        },
        formItemProps: {
          rules: [
            {
              required: true,
              message: "此项为必填项",
            },
          ],
        },
        options: {
          path: "/role",
          params: {
            is_all: 1,
          },
        },
        render:(text,row)=>{
          return <div className="centerl">
            {
              row?.roles?.map?.(it=>{
                return <Tag style={{display:"block"}}>{it?.role_name}</Tag>
              })
            }
          </div>
        }
      },
      {
        title: "性别",
        key: "sex",
        dataIndex: "sex",
        valueType: "radio",
        editable: false,
        render:(it,row)=>{
          return row.sex == '1'?'男':row.sex=='2'?'女':'-'
        },
        options: [
          {
            value: "1",
            label: "男",
          },
          {
            value: "2",
            label: "女",
          },
        ],
      },
      {
        title: "公司管理员",
        key: "is_admin",
        dataIndex: "is_admin",
        render: (text, row) => {
          return row?.is_admin ? "是" : "否";
        },
        hideInForm: true,
      },
      {
        title: "微信昵称",
        key: "nick_name",
        dataIndex: "nick_name",
        ellipsis: true,
        hideInTable: true,
        hideInForm: true,
      },
      {
        title: "国家",
        key: "country",
        dataIndex: "country",
        ellipsis: true,
        hideInTable: true,
        hideInForm: true,
      },
      {
        title: "省份",
        key: "province",
        dataIndex: "province",
        ellipsis: true,
        hideInTable: true,
        hideInForm: true,
      },
      {
        title: "城市",
        key: "city",
        dataIndex: "city",
        ellipsis: true,
        hideInTable: true,
        hideInForm: true,
      },
      {
        title: "生日",
        key: "birthday",
        dataIndex: "birthday",
        ellipsis: true,
        valueType: "date",
        hideInTable: true,
        hideInForm: true,
      },
      {
        title: "状态",
        key: "enable",
        dataIndex: "enable",
        valueType: "radio",
        formItemProps: {
          rules: [
            {
              required: true,
              message: "此项为必填项",
            },
          ],
        },
        options: [
          {
            label: "启用",
            value: true,
          },
          {
            label: "停用",
            value: false,
          },
        ],
        render: (text, row) => {
          return (
            <Switch
              checked={row?.enable}
              onChange={(val) => enable(val, row?.id)}
            />
          );
        },
      },
    ],
    pathconfig: {
      enableadd: true,
      enableedit: true,
      enabledelete: true,
      enabledetail: true,
      add: "/company/create_user",
      edit: "/company/update_user",
      list: "/user",
      delete: "/company/del_user",
      detail: "",
    },
  };
}
export default getcolumns;
